<?php

/**
 * Class News
 * @property $id
 * @property $titre
 * @property $corp
 * @property $date DateTime
 * @property $auteur
 */
class News {

// <editor-fold defaultstate="collapsed" desc="Champs">

    private $_id = 0;
    private $_titre = "inconnu";
    private $_corp = "inconnu";
    /**
     * @var $_date DateTime
     */
    private $_date = "inconnu";
    private $_auteur = "inconnu";
    private $_image = "defaut_news.jpg";

// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Propriétés">

    public function __get($property){
        switch ($property){
            case "id": return $this->_id;
                break;
            case "titre": return $this->_titre;
                break;
            case "corp": return $this->_corp;
                break;
            case "date": return $this->_date;
                break;
            case "auteur": return $this->_auteur;
                break;
            case "image": return $this->_image;
                break;
            default: throw new Exception("Propriété '$property' n'existe pas");
        }
    }

    public function __set($property, $value){
        switch($property){
            case "id": $this->_id = $value;
                break;
            case "titre": $this->_titre = $value;
                break;
            case "corp": $this->_corp = $value;
                break;
            case "date": $this->_date = $value;
                break;
            case "auteur": $this->_auteur = $value;
                break;
            case "image": $this->_image = $value;
                break;
            default: throw new Exception("Propriété '$property' n'existe pas");
        }
    }

// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Constructeur">
    /**
     * @param $titre
     * @param $corp
     * @param $date DateTime
     * @param $auteur
     * @param null $id
     */
    public function __construct($titre, $corp, $date, $auteur, $image, $id = null){
        $this->id = ($id==null)?null: $id;
        $this->titre = $titre;
        $this->corp = $corp;
        $this->date = $date;
        $this->auteur = $auteur;
        $this->image = $image;
    }

// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Methodes">
    /**
     * @param $date DateTime
     * @return bool|string
     */
    public function formatDate($date){
        $format = date_format($date, 'dd-mm-YYY');
        return $format;
    }


    public function __tostring(){
        $textHTML = "";
        $textHTML .= "<div id='uneNews'>";
        $textHTML .= "<img src='$this->image' class='imgNews'/>";
        $textHTML .= "<p class='news'>";
        $textHTML .= "<h1>$this->titre</h1>";
        $textHTML .= "<p>$this->corp</p>";
        $textHTML .= "<h2>$this->date";
        $textHTML .= " par $this->auteur</h2></p>";
        $textHTML .= "</div>";

        return $textHTML;
    }

// </editor-fold>

}

?>